import gameConfig from '../../engines/configs/gameConfig';
import O1HD, { managers, modules, services } from '../../engines/gameEngine';
import node_component from '../../engines/libs/node_component';
import { REWARD_TYPE } from '../../engines/services/userContent/userInterface';
import PageBase from '../Base/PageBase';
import { GAME_EVENT } from '../Enum';
import { ITipsPagePrams } from '../Interface';
import mainRoot from '../MainRoot';
//电子邮件puhalskijsemen@gmail.com
//源码网站 开vpn全局模式打开 http://web3incubators.com/
//电报https://t.me/gamecode999
//网页客服 http://web3incubators.com/kefu.html
const {ccclass, property,menu , disallowMultiple} = cc._decorator;

@ccclass
@disallowMultiple
@menu('游戏页面/添加桌面快捷')
export default class AddDestokPage extends cc.Component{

    private readonly  FirstKey:string="get-First-Add"


    @property({type:cc.Label,displayName:"奖励数"})
    private rewardNum : cc.Label = null;

    private tt :any = null

    protected onLoad(): void {
        this.rewardNum.string = gameConfig.ADD_ONCE_POWER.toString();
        this.tt =window['tt']

        //字节跳动 字节跳动lite 和西瓜拒审 关闭

        if(!mainRoot.isShortcutOpen()) {
            this.node.destroy();
        }

    }

    OnAddBtn(){
        managers().soundMgr.playSound("mainSound/anNiu");

        console.info("添加快捷方式 onBtnMe")
        // O1HD.getModules().uiControlModule.showMessageBox("添加失败");
        let self=this
        if( this.tt){
            console.info("添加快捷方式AddDestokPage")
            this.tt.addShortcut({
                success: function (res) {
                    let key=O1HD.getServices().localStorageSrv.getStorage(self.FirstKey);
                    if(key&&Number(key)==1)
                    {
                        console.info("已经添加过快捷方式")
                    }else
                    {
                        console.info("添加快捷方式成功")
                        self.addRewarded()
                        O1HD.getServices().localStorageSrv.setStorage(self.FirstKey,1);
                        O1HD.getServices().miniGameSrv.getAppApiInstance().reportAnalytics('addDestok',{addDestok:"添加桌面界面成功"} );
                   
                    }
                },
                fail: function (res) {
                    console.info("添加快捷方式失败",res)
                    O1HD.getServices().miniGameSrv.getAppApiInstance().reportAnalytics('addDestok',{addDestok:"添加桌面界面失败"} );
                    O1HD.getModules().uiControlModule.showMessageBox("添加失败");
                }
            })
        }else{
            this.addRewarded()
            O1HD.getServices().localStorageSrv.setStorage(self.FirstKey,1);
        }


        this.node.destroy();
    }


    addRewarded(){
        services().userSrv.addPowerOfVideo();
        modules().uiControlModule.showGetRewarded(REWARD_TYPE.POWER,gameConfig.ADD_ONCE_POWER,"恭喜");
    }

    onClose(){
        O1HD.getServices().miniGameSrv.getAppApiInstance().reportAnalytics('addDestok',{addDestok:"添加桌面界面取消"} );
        this.node.destroy();
    }
}